package com.hnkywl.sts.action.cwgl.kmys;

import com.hnkywl.sts.entity.cwgl.kmys.Tyfzhsmc;
import com.hnkywl.sts.entity.sys.Js;
import com.hnkywl.sts.service.cwgl.kmys.TyfzhsmcService;
import com.hnkywl.sts.service.sys.JsService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 说明：
 * 包:        com.hnkywl.sts.action.sys
 * 类描述:    角色Action类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Namespace("/cwgl/kmys/tyfzhsmc")
public class TyfzhsmcAction extends SimpleActionSupport {
    private TyfzhsmcService tyfzhsmcService;
    //角色名称
    private String mc;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    //传入的角色实体
    private Tyfzhsmc tyfzhsmc;
    //传入的角色Id值
    private Long tyfzhsmcId;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;

    private Long mcId;

    /**
     * 方法名:     获取通用辅助核算
     * 功能描述:      获取通用辅助核算
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hfj
     * 创建日期:   13-2-19上午10:47
     * 修改人:     hfj
     * 修改日期:   13-2-19上午10:47
     */
    @Action("tyfzhsmcList")
    public void tyfzhsmcList() {
        this.renderJson(this.tyfzhsmcService.findTyfzhsmcMc(mc, page, rows));
    }

    @Action("get_tyfzhsmctree")
    public void getTyfzhsmctree() {
        if (request.getParameter("id") == null) {
            StringBuilder sb = new StringBuilder("[{\"id\": \"ddl\", \"text\": \"辅助核算映射\", \"attributes\": {\"code\": \"null\", \"children\": \"false\"}, \"state\": \"open\",\"children\":");
            String treeJson = "[{\"id\":\"dl:xm\",\"text\":\"项目\",\"attributes\":{\"code\":\"null\",\"children\":\"true\"},\"state\":\"closed\"}," +
                    "{\"id\":\"dl:xjllxm\",\"text\":\"现金流量项目\",\"attributes\":{\"code\":\"null\",\"children\":\"true\"},\"state\":\"closed\"}," +
                    "{\"id\":\"dl:fzhs\",\"text\":\"辅助核算\",\"attributes\":{\"code\":\"null\",\"children\":\"true\"},\"state\":\"closed\"}]";
            sb.append(treeJson).append("}]");
            renderHtml(sb.toString());
        } else {
            String[] values = request.getParameter("id").split(":");
            String dl = String.valueOf(values[1]);
            this.renderJson(this.tyfzhsmcService.findAllTyfzhsmcTree(dl));
        }
    }

    @Action("get_tyfzhsmctreejson")
    public void getTyfzhsmctreejson() {
        this.renderJson(this.tyfzhsmcService.findAllTyfzhsmcTreeJson());
    }





    @Action("get_tyfzhsmcdl")
    public void getTyfzhsmcdl() {
        this.renderJson(this.tyfzhsmcService.getTyfzhsmcdl(mcId));
    }


    //判断页面跳转
    @Action("tyfzhsmc_content")
    public String tyfzhsmcContent() {
        if (tyfzhsmcId != null)
            tyfzhsmc = tyfzhsmcService.findTyfzhsmcDetail(tyfzhsmcId);
        return SUCCESS;
    }


    /**
     * 方法名:     增添角色
     * 功能描述:      向数据库插入角色
     * 输入参数:    <@param Js js实例>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hfj
     * 创建日期:   13-2-19上午10:47
     * 修改人:     hfj
     * 修改日期:   13-2-19上午10:47
     */
    @Action("add_tyfzhsmc")
    public void addTyfzhsmc() {
        try {
            tyfzhsmcService.saveTyfzhsmc(tyfzhsmc);
            renderText("{\"statusCode\":\"200\", \"message\":\"保存通用辅助核算成功\", \"operationType\":\"add\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     删除角色
     * 功能描述:      删除角色
     * 输入参数:    <@param jsId>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hfj
     * 创建日期:   13-2-19上午10:47
     * 修改人:     hfj
     * 修改日期:   13-2-19上午10:47
     */

    @Action("delete_tyfzhsmc")
    public void deleteTyfzhsmc() {
        try {
            tyfzhsmcService.deleteTyfzhsmc(tyfzhsmcId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除通用辅助核算成功\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }

    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void ajaxValidate() {
        if (!tyfzhsmcService.ajaxValidate(tyfzhsmcId,validateVal,validateField))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }

    //============getter setter============


    public String getMc() {
        return mc;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Tyfzhsmc getTyfzhsmc() {
        return tyfzhsmc;
    }

    public void setTyfzhsmc(Tyfzhsmc tyfzhsmc) {
        this.tyfzhsmc = tyfzhsmc;
    }

    public Long getTyfzhsmcId() {
        return tyfzhsmcId;
    }

    public void setTyfzhsmcId(Long tyfzhsmcId) {
        this.tyfzhsmcId = tyfzhsmcId;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public Long getMcId() {
        return mcId;
    }

    public void setMcId(Long mcId) {
        this.mcId = mcId;
    }

    @Autowired
    public void setTyfzhsmcService(TyfzhsmcService tyfzhsmcService) {
        this.tyfzhsmcService = tyfzhsmcService;
    }
}
